home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / NextDeveloper / Headers / kernserv / c_utils.h next >
C/C++ Source or Header  |  1995-02-14  |  931b  |  37 lines

  1. /* 
  2.  * Copyright (c) 1992 NeXT, Inc.  All rights reserved.
  3.  *
  4.  * c_utils.h -- Helpful C macros
  5.  */
  6.  
  7. #define    ROUND_UP(addr, align)    \
  8.     ( ( (unsigned)(addr) + (align) - 1) & ~((align) - 1) )
  9.  
  10. #define    TRUNC_DOWN(addr, align)    \
  11.     ( (unsigned)(addr) & ~((align) - 1) )
  12.  
  13. /*
  14.  * FIXME: For some reason the compiler miscalculates the alignment of
  15.  * struct uthread as 0, so this forces all structs to have an alignof of
  16.  * 16.
  17.  */
  18. #define    COMPILER_BUG    1
  19.  
  20. #ifdef    COMPILER_BUG
  21. #define    ROUND_PTR(type, addr)    \
  22.     (type *)( ( (unsigned)(addr) + 16 - 1) \
  23.           & ~(16 - 1) )
  24.  
  25. #define    TRUNC_PTR(type, addr)    \
  26.     (type *)( (unsigned)(addr) & ~(16 - 1) )
  27. #else    COMPILER_BUG
  28. #define    ROUND_PTR(type, addr)    \
  29.     (type *)( ( (unsigned)(addr) + __alignof__(type) - 1) \
  30.           & ~(__alignof__(type) - 1) )
  31.  
  32. #define    TRUNC_PTR(type, addr)    \
  33.     (type *)( (unsigned)(addr) & ~(__alignof__(type) - 1) )
  34. #endif    COMPILER_BUG
  35.  
  36. #define    ARRAY_ELEM(x)        (sizeof(x)/sizeof(x[0]))
  37.